package com.zhuoshi.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zhuoshi.entity.Client;
import com.zhuoshi.entity.Marketing;
import com.zhuoshi.entity.MarketingVoPo;
import com.zhuoshi.entity.Receive;
import com.zhuoshi.entity.User;
import com.zhuoshi.mapper.MarketingCustomMapper;
import com.zhuoshi.service.ClientService;
import com.zhuoshi.service.MarketingService;
import com.zhuoshi.service.UserService;
/*
 * Author 海生
 * 
 * 
 */
@Controller
@RequestMapping(value="marketing")
public class MarketingController {

	@Autowired
	private MarketingService marketingService;
	@Autowired
	private ClientService clientService;
	@Autowired
	private UserService userService;
	
	//查询所有接待记录
	@RequestMapping("jiedaijilu.action")
	public ModelAndView selectJieDaiJiLuAll() throws Exception{
		List<MarketingVoPo> marketingList = marketingService.selectJiLuAll();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("marketingList", marketingList);
		modelAndView.setViewName("/Admin/JieDaiJiLu.jsp");
		return modelAndView;
	}
	
	//删除客户接待记录
	@RequestMapping("DeleteKuhujiedai.action")
	public String deleteKuhujiedaiLu(int id) throws Exception{
		int rows = marketingService.deleteKuhujiedaiLu(id);
		System.out.println("controller层..删除."+rows);
		String path ="";
		if(rows>0){
			path = "redirect:jiedaijilu.action";
		}else{
			path = "/error.jsp";
		}
		return path;
	}
	
	//批量删除客户接待记录
	@RequestMapping("DeleteAllKuhujiedai.action")
	public String DeleteAllKuhujiedai(String [] id) throws Exception{
		int rows = marketingService.DeleteAllKuhujiedai(id);
		System.out.println("controller层..."+rows);
		if(rows>0){
			return "redirect:jiedaijilu.action";
		}else{
			return "/error.jsp";
		}					
	}
	
	//查询显示客户姓名和业务员接待记录
	@RequestMapping("selectByNameAndUsername.action")
	public ModelAndView selectByNameAndUsername() throws Exception{
		//List<MarketingCustomMapper> marketingList = marketingService.selectByNameAndUsername();
		List<Client> clientList = clientService.selectClientAllLu();
		List<User> userList = userService.selectUserAll();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("clientList", clientList);
		modelAndView.addObject("userList", userList);
		modelAndView.setViewName("/Admin/addKuhujilu.jsp");
		return modelAndView;
	}
	
	//添加客户接待记录
	@RequestMapping("addKuhujiedaijilu.action")
	public String addKuhujiedaijilu(Marketing marketing) throws Exception{
		int rows = marketingService.addKuhujiedaijilu(marketing);
		System.out.println("添加...."+rows);
		if(rows>0){
			return "redirect:jiedaijilu.action";
		}else{
			return "/error.jsp";
		}
	}
	
	//根据id查询一条接待记录
	@RequestMapping("selectKuHuJieDaijilu.action")
	public String selectJiDaijiluById(Model model,int id) throws Exception{		
		MarketingVoPo marketingvopo = marketingService.selectJiDaijiluById(id);
		System.out.println("id查询单条记录....");
		model.addAttribute("marketingvopo", marketingvopo);		
		return "/Admin/updateKuHujiedaijilu.jsp";
	}
	
	//修改客户接待记录
	@RequestMapping("updateKuhujiedaijilu.action")
	public String updateKuhujiedaijilu(MarketingVoPo marketingvopo) throws Exception{
		int rows = marketingService.updateKuhujiedaijilu(marketingvopo);
		if(rows>0){
			return "redirect:jiedaijilu.action";
		}else{
			return "/error.jsp";
		}		
	} 
}
